require("../../$res/plugin/jstree");
module.exports = {
    template: require("./tpl/tree.htm"),
    props: {
        type: String,
        value: Array,
        body: Object
    },
    data: function () {
        return {
            res: new Date().getTime()
        }
    },
    mounted: function () {
        var $this = this,
            ele = '#' + $this.type + $this.res;
        $(ele).jstree({
            'core': {'data': [$this.body]}
        }).on("changed.jstree", function (e, data) {
            if (data.action === 'select_node') {
                var key = data.node.id,
                    item = data.node.text;
                $this.body.selected = key;
                $$.sessionStore('dpt', $this.body);
                $this.$emit("input", [key, item]);
            }
        }).on('loaded.jstree', function (e, data) {
            var tree = $$.sessionStore('dpt');
            if (tree)
                data.instance.select_node(tree.selected);
        });
    }
};
